﻿/*  
 * 作者: Elan
 * 创建时间: 2013-5-2 20:49:36  
 
 * 说明:   玲珑数据信息系统主窗体
 */

using System;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using Microsoft.Practices.Unity;
using NanoERP.Command;
using NanoERP.Infrastructure;
using WeifenLuo.WinFormsUI.Docking;
using System.ComponentModel;
using LL.Utility.WindowsForms;

namespace NanoERP
{
    public partial class MainForm : Office2007Form, IWorkbench
    {
        //定义全局变量保存用户的信息
        public string UserName = "";

        protected override void OnLoad(EventArgs e)
        {
            Initlize();
            base.OnLoad(e);
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            e.Cancel = !MessageDialogHelper.ConfirmYesNo("是否确认退出？");
            base.OnClosing(e);
        }

        public MainForm()
        {
            InitializeComponent();
        }


        #region IWorkspace

        /// <summary>
        /// 通知工作台加载模块窗体
        /// </summary>
        /// <param name="moduleCode">模块代码</param>
        /// <param name="command">命令参数</param>
        public void LoadModule(string moduleCode, LoadModuleCommand command)
        {
            var frm = ModuleContainer.Resolve<ModuleForm>(moduleCode);
            //下面的方法待修改
            ShowMdiChild(frm);
        }

        /// <summary>
        /// 向MDI窗体广播消息
        /// </summary>
        /// <param name="message"></param>
        public void BroadcaseMessage(ModuleMessage message)
        {

        }

        private void ShowMdiChild(DockContent form)
        {
            //判断窗体是否重复打开
            foreach (var item in this.MdiChildren)
            {
                if (item.Name.Equals(form.Name))
                {
                    item.Activate();
                    return;
                }
            }

            form.Show(this.ContentPanel);
        }

        //主窗体关闭事件
        private void MianForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult result = MessageBoxEx.Show("\n欢迎再次使用玲珑信息管理系统   \n\n\n    确认是否退出(Y/N)", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (result == DialogResult.OK)
            {
                e.Cancel = false;
                this.Dispose();
                Application.Exit();
            }
            else
            {
                e.Cancel = true;
            }

        }

        private void Exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //退出系统
        private void toolStripExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void timerHY_Tick(object sender, EventArgs e)
        {
            this.da.Text = "系统时间:" + System.DateTime.Now.ToString();
        }
        #endregion
    }
}